package cn.wuxun.review.service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.wuxun.common.pojo.Review;
import cn.wuxun.review.mapper.ReviewMapper;

@Service
public class ReviewService {
	@Autowired
	private ReviewMapper reviewMapper;
	// 根据新闻nid,查看当前新闻的评论
	public List<Review> queryReviewsByNid(String nid) {
		List<Review> list = reviewMapper.queryReviews(nid);
		return list;
	}
	
	//添加评论
	public void addReview(Review review) {
		review.setRid(UUID.randomUUID().toString());
		review.setRtime(new Date());
		reviewMapper.addReview(review);
	}
	
	//删除评论
	public void delReview(String rid) {
		reviewMapper.delReview(rid);
	}

	// 修改评论
	public void updateReview(Review review) {
		review.setRid(UUID.randomUUID().toString());
		review.setRtime(new Date());
		reviewMapper.updateReview(review);
	}

	public Integer queryReviewNum(String nid) {
		return reviewMapper.queryReviewNum(nid);
	}
}
